package com.melodyframe.stage.spring;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.support.AbstractApplicationContext;

public abstract class AbstractSpringStageModule extends AbstractSpringStage
		implements ApplicationContextAware {

	private ApplicationContext			parent;
	private AbstractApplicationContext	applicationContext;

	@Override
	public void setApplicationContext(ApplicationContext parent)
			throws BeansException {
		this.parent = parent;
		AbstractApplicationContext applicationContext = this
				.createSubApplicationContext();
		applicationContext.setParent(this.parent);
		applicationContext.refresh();
		this.applicationContext = applicationContext;
	}

	public ApplicationContext getParent() {
		return parent;
	}

	@Override
	public ApplicationContext getApplicationContext() {
		return applicationContext;
	}

	public abstract AbstractApplicationContext createSubApplicationContext();

}
